package com.me.forum.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.me.forum.dao.IPageDao;
import com.me.forum.domain.Page;
import com.me.forum.request.PageRequest;
import com.me.forum.service.IPageService;
import com.me.forum.utils.TypeConversion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PageService extends BaseService<IPageDao, Page> implements IPageService {
	@Autowired
	private PlateService plateService;


	//获取最新帖子 by Orange
	@Override
	public IPage<Page> getAll(PageRequest preq, String _page, String _size) {
		Long page = TypeConversion.toLong(_page);
		Long size = TypeConversion.toLong(_size);

		return dao.selectByAll(new com.baomidou.mybatisplus.extension.plugins.pagination.Page(page,size), preq);
	}

	@Override
	public boolean addPage(PageRequest preq) {
		if (!preq.isLegal()) {
			return false;
		}
        int save = dao.insertSelective(preq);
//        if (preq.getPageTypeId() != null && preq.getPageTypeId().isEmpty() ||
//                preq.getPlateId() != null && preq.getPlateId().isEmpty() ||
//                preq.getUserId() != null && preq.getUserId().isEmpty()) {
//            dao.insertByRole(preq);
//        }
        return save == 1;
	}

//	@Override
//	public boolean updateByTitle(PageRequest preq) {
//		return false;
//	}

	@Override
	public boolean updateByTitle(PageRequest preq) {
		if (!preq.isLegal()) {
			return false;
		}
		return dao.updateByPageId(preq) == 1;
	}

}
